<div class="content-wrapper">
    <section class="content-header">
        <h1>{$docInfo?'编辑':'新增'}文档</h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">文档管理</li>
            <li class="active">{$docInfo?'编辑':'新增'}文档</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <input type="hidden" name="id" id="id" value="{$docInfo.id}" />
                    <div class="form-group">
                        <label for="name" class="col-sm-3 control-label"> 名称 </label>
                        <div class="col-sm-6">
                            <input class="form-control" id="name" name="name" value="{$docInfo.name}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="file_path" class="col-sm-3 control-label"> URL </label>
                        <div class="col-sm-6">
                            <input id="file_path" name="file_path" class="form-control" value="{$docInfo.file_path}" disabled readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="upload" class="col-sm-3 control-label"> 文件上传 </label>
                        <div class="col-sm-6">
                            <input id='upload' name="file_upload" type="button" value='上传' class='btn btn-sm btn-success'>
                            <span class="label label-warning pull-right">可上传Excel、word、pdf 文档</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="status" class="col-sm-3 control-label"> 状态 </label>
                        <div class="col-sm-6">
                            <select id="status" name="parent_cid" class="form-control">
                                <option value="1" <if condition="$docInfo.status eq 1 ">selected</if>>开启</option>
                                <option value="2" <if condition="$docInfo.status eq 2 ">selected</if>>关闭</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="form-field-1" class="col-sm-3 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-info btn-sm save-btn">提交</button>
                            &nbsp;
                            <button type="reset" class="btn btn-sm">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script src="__PUBLIC__/global/AjaxUpload.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script type="text/javascript">
    //异步上传文件
    new AjaxUpload("#upload", {
        action: '/admin/index/ajaxUploadFile',
        type:"POST",
        name:'import',
        data:{doc: 'doc'},
        responseType: 'json',
        onSubmit: function(file, ext) {
            if("xls,xlsx,doc,pdf,docx".indexOf(ext)<0){
                layer.msg("请上传xls/xlsx/doc/docx/pdf格式的文件");
                return false;
            }
            layer.load(1, {
                shade: [0.48,'#999'] //0.1透明度的白色背景
            });
        },
        onComplete: function(file, response) {
            layer.closeAll('loading');
            if(response.Code ==999) {
                var file =response.Data.file;
                layer.msg('上传成功');
                $("#file_path").val(file)
                //window.location.reload(true);
            }else{
                layer.msg(response.Msg);
                return false;
            }
        }
    });

    //添加
    $(".save-btn").click(function () {
        var id = $("#id").val();
        var name = $("#name").val();
        var file_path = $("#file_path").val();
        var status = $("#status").val();

        if(name==''){
            layer.msg('请填写文档名称',{time:1000});
            $('#name').focus();
            return false;
        }
        if(file_path==''){
            layer.msg('请上传文档',{time:1000});
            $('#file_path').focus();
            return false;
        }
        $.post('/admin/document/ajaxSaveDoc',{
            id: id,
            name: name,
            file_path: file_path,
            status: status
        },function (_data) {
            if(_data.Code==999){
                layer.msg("操作成功",{time:1000});
                window.location.href = '/admin/document/docList'
            }else{
                layer.msg(_data.Msg,{time:1000});
                return false;
            }
        },"JSON");
    });
</script>